
const Natatorium = require('../../util/natatorium') //游泳馆 schema

let natatorium = (router, opt) => {
	// 获取场馆列表
	router.post('/getNatatoriumList', async(ctx, next) => {
	    var arr = [],
	      res = await opt.findAll(Natatorium);

	    ctx.body = {
	      res: res,
	      status: 200
	    }

	  })
	  // 获取场馆详细
	router.post('/getNatatoriumDetail', async(ctx, next) => {

	  var res = await opt.findById(Natatorium, ctx.request.body.id)

	  ctx.body = {
	    res: res,
	    status: 200
	  }

	})

	//设置场馆信息接口
	router.post('/setNatatoriumDetail', async(ctx, next) => {
	  var {body} = ctx.request;
    
	  var result = await opt.insert(Natatorium, body);
	  ctx.body = {
	    res: '设置场馆信息接口',
	    status: 200,
	    data: result
	  }
	})

	//更新场馆信息
	router.post('/updateNatatoriumDetail', async(ctx, next) => {
	  console.log('更新场馆信息', ctx.request.body)
	  let {body} = ctx.request
	  var result = await opt.findByIdAndUpdate(Natatorium, body.id, body.data)
	  .then(res =>  res, err => err)
	  ctx.body = {
	    res: '更新场馆信息',
	    status: 200,
	    result: result
	  }
	})

	//报名页面请求数据接口
router.post('/getSignUpInfo', async(ctx, next) => {
  let {body} = ctx.request
  // 查询场馆
  var nataArr = await opt.find(Natatorium, {_id: body.id})
  //返回场馆列表
  ctx.body = nataArr
  ctx.status = 200
})
}

module.exports = natatorium